package com.example.designpatterns.flyweight;

// 具体享元类
public class Rectangle implements Shape {
    // 内部状态
    // 矩形的颜色
    private String color;
    // 矩形的宽度
    private int width;
    // 矩形的高度
    private int height;
    
    // 构造函数设置内部状态
    public Rectangle(String color, int width, int height) {
        this.color = color;
        this.width = width;
        this.height = height;
        // 模拟对象创建的开销
        System.out.println("创建 " + color + " 矩形对象，宽: " + width + ", 高: " + height);
    }
    
    // 使用外部状态绘制矩形
    @Override
    public void draw(int x, int y) {
        System.out.println("绘制 " + color + " 矩形: 左上角坐标(" + x + ", " + y + 
                "), 宽: " + width + ", 高: " + height);
    }
} 